<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="供应商" prop="provide">
        <el-input v-model="queryParams.provide" placeholder="请输入供应商" />
      </el-form-item>
      <el-form-item label="所属公司" prop="provideGroup">
        <el-select v-model="queryParams.company" filterable placeholder="请选择公司" clearable >
          <el-option v-for="item in companyType" :key="item.label" :label="item.value" :value="item.label">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="仓库名称" prop="productWare">
        <el-select v-model="queryParams.productWare" filterable placeholder="请选择仓库" clearable >
          <el-option v-for="item in productWare" :key="item.label" :label="item.value" :value="item.label">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="可开金额" prop="checkMoney">
        <el-select v-model="queryParams.checkMoney" filterable placeholder="请选择可开金额" clearable >
          <el-option v-for="item in checkMoneyList" :key="item.value" :value="item.value" :label = "item.label">{{item.label}}</el-option>        
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:MaterialsInvoicingSummary:Export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="GoodsBilling" border class="table">
      <el-table-column prop="index" label="序号" width="55" align="center"></el-table-column>
      <el-table-column label="供应商" prop="provide" align="center">
      </el-table-column>
      <el-table-column label="仓库名称" align="center" prop="productWare">
        <template slot-scope="scope">
            <div v-if="scope.row.productWare==='中心库'" class="DataCenter">
            <el-image :src="zxkImg" class="zxkImg"></el-image>
            <span class="text">{{ scope.row.productWare }}</span>
          </div>
          <div v-if="scope.row.productWare==='配件库'" class="DataCenter">
            <span class="text1">{{ scope.row.productWare }}</span>
          </div>

        </template>
      </el-table-column>
      <el-table-column label="分类" align="center" prop="productGroup">
        <template slot-scope="scope">
            <div v-if="scope.row.productGroup==='配件'" class="DataCenter">
            <el-image :src="pjImg" class="zxkImg"></el-image>
            <span class="text1">{{ scope.row.productGroup }}</span>
          </div>
          <div v-if="scope.row.productGroup==='轮胎'" class="DataCenter">
            <el-image :src="ltImg" class="pjkImg"></el-image>
            <span class="text1">{{ scope.row.productGroup }}</span>
          </div>
          <div v-if="scope.row.productGroup==='制冷剂'" class="DataCenter">
            <el-image :src="zljImg" class="zxkImg"></el-image>
            <span class="text1">{{ scope.row.productGroup }}</span>
          </div>
          <div v-if="scope.row.productGroup==='润滑油'" class="DataCenter">
            <el-image :src="yhyImg" class="pjkImg"></el-image>
            <span class="text1">{{ scope.row.productGroup }}</span>
          </div>
          </template>
      </el-table-column>
      <el-table-column label="所属公司" prop="company" align="center">
      </el-table-column>
      <el-table-column label="可开金额" align="center" prop="moeny">
        <template slot-scope="scope">
          <span  style="  float: right;color: red;">{{ formatNumber(parseFloat(scope.row.moeny).toFixed(2)) }}</span>
        </template>
      </el-table-column>
      <el-table-column  label="操作" align="center" width="150">
        <template slot-scope="scope">
          <el-button @click="pushBilling(scope.row)" style="font-size:13px" icon="el-icon-document" type="text" size="small">详情</el-button>
        </template>
      </el-table-column>

    </el-table>
    <pagination v-show="total > 0" layout="total, sizes, prev, pager, next, jumper" :total="total"
      :page.sync="queryParams.pageNum" @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :limit.sync="queryParams.pageSize" @pagination="getList" />

  </div>
</template>

<script>
import { invoicingList1 } from "@/api/system/supplierBillingDetail";
export default {
  name: "MaterialsInvoicingSummary",
  data() {
    return {
      zxkImg: require('../../../assets/icon/zxk.png'),
      pjImg: require('../../../assets/icon/pj.png'),
      ltImg: require('../../../assets/icon/lt.png'),
      zljImg: require('../../../assets/icon/zlj.png'),
      yhyImg: require('../../../assets/icon/yhy.png'),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供应商付款表格数据
      GoodsBilling: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        provide: "",
        company:"",
        productWare:"",
        checkMoney:""
      },
      deptName: "",
      companyType:[
        { value: '营运公司', label: '营运公司' },
        { value: '金山巴士', label: '金山巴士' },
        { value: '崇明巴士', label: '崇明巴士' }
      ],
      productWare:[
        { value: '中心库', label: '中心库' },
        { value: '配件库', label: '配件库' },
      ],
      checkMoneyList: [
        { value: '', label: '全部' },
        { value: '1', label: '非零' },
        { value: '0', label: '为零' },
      ]
      // fisrtActivate: true
    };
  },
  created() {
    this.eventHnadling();
  },
  // activated() {
  // let kpStatus =  this.$store.state.tagsView.kpStatus;
  //   if (!this.fisrtActivate) {
  //     if(kpStatus=='1'){
  //     this.eventHnadling();
  //     this.$store.commit('tagsView/SET_KP_STATUS', 0);
  //     }
  //   } else {
  //     // 防止 重复请求
  //     this.fisrtActivate = false;
  //   }


  // },
  methods: {
    eventHnadling() {
      const User = localStorage.getItem('User');
      this.deptName = JSON.parse(User).dept ? JSON.parse(User).dept.deptName : '';
      if (this.deptName !== '物资公司') {
        this.queryParams.provide = this.deptName;
      } else {
        this.queryParams.provide = "";
      }
      this.getList();
    },
    /** 查询供应商付款列表 */
    getList() {
      this.loading = true;
      invoicingList1(this.queryParams).then(response => {
        console.log(response)
        if (response.code === 200) {
          this.GoodsBilling = response.data;
          this.GoodsBilling.forEach((item, index) => {
            item.index = (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
          })
          this.total = response.total
        }
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.provide = "";
      this.queryParams.company="";
      this.handleQuery();
    },

    // 分页
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
    },


    /** 导出按钮操作 */
    handleExport() {
      this.download('system/invoicing/export', {
        ...this.queryParams
      }, `物资开票汇总${new Date().getTime()}.xlsx`)
    },
    // 数字转换
    formatNumber(value) {
      if (value) {
        let [integerPart, decimalPart] = value.toString().split('.');
        let formattedNumber = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',') + '.' + decimalPart.slice(0, 3);
        return formattedNumber;
      }
    },
    // 跳转开票流水
    pushBilling(item) {
      this.$router.push({
        name: 'BillingAccount', query: {
          provide: item.provide, productGroup: item.productGroup, productWare: item.productWare,company:item.company
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>


.table {
  .el-table__body-wrapper {
    // height: 650px !important;
    overflow-y: auto !important;
  }
}
.zxkImg{
  width: 30px;
  height: 30px;
}
.DataCenter{
  display: flex;
    justify-content: center;
    align-items: center;
}
.text{
  margin-top: 10px;
}
.pjkImg{
  width: 28px;
  height: 28px;
}
.text1{
  margin-top: 2px;
  margin-left: 5px;
}
</style>
